package com.test.spring.fusion.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.test.spring.fusion.service.StoreFileCrudService;
@Service
public class StoreFileCrudServiceImpl implements StoreFileCrudService {

	@Autowired
	private Environment env;
	@Autowired
	public FastFileStorageClient fastFileStorageClient;
	
	@Override
	public String fileUpload(MultipartFile file) {
		StorePath storePath=null;
		String originalFilename = file.getOriginalFilename();
		String fileName= originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
		try {
			storePath=fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(),fileName,null);
		} catch (Exception e) {
			throw new RuntimeException("文件上传异常:"+e.getMessage());
		}
		String filePath=env.getProperty("file.path");
		return filePath+storePath.getPath();
	}
}
